package com.example.android_little_game

import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import android.widget.Button
import android.widget.TextView

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        supportActionBar?.hide()
        refreshInfo()

        /* 修改信息 */
        findViewById<Button>(R.id.btn_edit).setOnClickListener {
            startActivity(Intent(this, SecondActivity::class.java))
        }

        /* 新增：开始游戏 */
        findViewById<Button>(R.id.btn_game).setOnClickListener {
            startActivity(Intent(this, ThirdActivity::class.java))
        }
    }

    override fun onResume() {
        super.onResume()
        refreshInfo()   // 同步最高分
    }

    private fun refreshInfo() {
        findViewById<TextView>(R.id.textView_name).text          = getString(R.string.name) + "：" + PlayerData.name
        findViewById<TextView>(R.id.textView_id).text            = getString(R.string.id)   + "：" + PlayerData.id
        findViewById<TextView>(R.id.textView_gender).text        = getString(R.string.gender)+ "：" + PlayerData.gender
        findViewById<TextView>(R.id.textView_phone).text         = getString(R.string.phone) + "：" + PlayerData.phone
        findViewById<TextView>(R.id.textView_highest_score).text = getString(R.string.highest_score) + "：" + PlayerData.highScore
    }
}